<?php
/**
 *	Architect Framework
 *
 *	Architect Framework is a light weight object oriented web applications framework written for PHP 5.1.4 and later that provide the tools to develop and deploy a website or application fast and with as little code as possible.
 *
 *	@author Robin Grass, <hello@coffinboy.se>
 *	@link http://architect.kodlabbet.net
 *	@license http://www.opensource.org/licenses/gpl-3.0.html GNU General Public License (v. 3)
 */

/**
 *	Architect_ExceptionHandler
 *
 *	This class catches exceptions and converts errors to exceptions.
 *
 *	@package Exceptions
 *	@version 1.0
 *	@author Robin Grass, <hello@coffinboy.se>
 */
class Architect_ExceptionHandler {

	/**
	 *	catchException
	 *
	 *	This method catches and calls Blueprint_ExceptionHandler::printException
	 *
	 *	@param object $exception
	 */
	public static function catchException(Exception $exception) {
		self::printException($exception);
	}
	
	/**
	 *	catchError
	 *
	 *	This method throws an ErrorException.
	 *
	 *	@param int $code
	 *	@param string $message
	 *	@param string $file
	 *	@param int $line
	 *
	 *	@throws ErrorException
	 */
	public static function catchError($code, $message, $file, $line) {
		throw new ErrorException($message, 0, $code, $file, $line);
	}
	
	/**
	 *	printException
	 *
	 *	This method prints the exeption, if ARCH_DEBUG_MODE is on it var_dumps the exception object.
	 *
	 *	@param object $exception
	 */
	public static function printException(Exception $exception) {
		if(ARCH_DEBUG_MODE) {
			echo '<pre style="font: 13px monaco">';
			var_dump($exception);
			echo '</pre>';
		} else {
			$class = get_class($exception);
			$code = $exception->getCode();
			$message = htmlentities($exception->getMessage());
		
			echo "<strong>Uncaught {$class}</strong> [{$code}]<br />Message: {$message}<br />";	
		}
	}

}
?>